<?php
namespace Models;
use Phalcon\Db\RawValue;

class SettingProfile extends BaseModel {


    public function beforeValidationOnCreate()
    {
        if (!isset($this->param) || !$this->param) {
            $this->param = new RawValue('default');
        }
        if (!isset($this->description) || !$this->description) {
            $this->description = new RawValue('default');
        }
        if (!isset($this->default_value) || !$this->default_value) {
            $this->default_value = new RawValue('default');
        }
        if (!isset($this->required) || !$this->required) {
            $this->required = new RawValue('default');
        }
    }

    public function beforeValidationOnUpdate()
    {
        if (!isset($this->param) || !$this->param) {
            $this->param = new RawValue('default');
        }
        if (!isset($this->description) || !$this->description) {
            $this->description = new RawValue('default');
        }
        if (!isset($this->default_value) || !$this->default_value) {
            $this->default_value = new RawValue('default');
        }
        if (!isset($this->required) || !$this->required) {
            $this->required = new RawValue('default');
        }
    }

    public function notSave()
    {
        //Obtain the flash service from the DI container
        $flash = $this->getDI()->getFlash();

        //Show validation messages
        foreach ($this->getMessages() as $message) {
            $flash->error($message);
        }
    }

}